# Build stage
FROM golang:1.23-alpine AS builder

WORKDIR /build

# Install dependencies
RUN apk add --no-cache git

# Copy go.work and all modules
COPY go.work ./
COPY proto/go.mod proto/go.sum ./proto/
COPY shared/go.mod shared/go.sum ./shared/
COPY services/ai-gateway/go.mod services/ai-gateway/go.sum ./services/ai-gateway/
COPY services/alert-service/go.mod services/alert-service/go.sum ./services/alert-service/
COPY services/api-gateway/go.mod services/api-gateway/go.sum ./services/api-gateway/
COPY services/notification-service/go.mod services/notification-service/go.sum ./services/notification-service/
COPY services/ticket-service/go.mod services/ticket-service/go.sum ./services/ticket-service/

# Download dependencies
WORKDIR /build/services/notification-service
RUN go mod download

# Copy all source code
WORKDIR /build
COPY proto ./proto
COPY shared ./shared
COPY services/notification-service ./services/notification-service

# Build
WORKDIR /build/services/notification-service
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o notification-service ./cmd

# Runtime stage
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy binary from builder
COPY --from=builder /build/services/notification-service/notification-service .

# Expose gRPC port
EXPOSE 50053

CMD ["./notification-service"]
